﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QD.Tools
{
    public static class ButtonHelper
    {
        /// <summary>
        /// 设置按钮是否可以设置焦点
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="value"></param>
        public static void SetSelectable(this Button btn, bool value)
        {
            MethodInfo mi = btn.GetType().GetMethod("SetStyle", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
            mi.Invoke(btn, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
                null,
                new object[] { ControlStyles.Selectable, value },
                null);
        }
    }
}
